package com.sanyuan.cloud.module.system.convert.nongmo;

import cn.hutool.core.date.DatePattern;
import com.sanyuan.cloud.framework.common.util.collection.CollectionUtils;
import com.sanyuan.cloud.framework.common.util.object.BeanUtils;
import com.sanyuan.cloud.module.system.controller.admin.nongmo.dto.PositionUserDTO;
import com.sanyuan.cloud.module.system.controller.admin.nongmo.vo.PositionListVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @Description: PositionConvert
 * @Author: wuyuwei
 * @Date: 2025/3/20
 */
@Mapper
public interface PositionConvert {
    PositionConvert INSTANCE = Mappers.getMapper(PositionConvert.class);


    default List<PositionListVO> convertList(List<PositionUserDTO> list) {
        return CollectionUtils.convertList(list, user -> convert(user));
    }

    default PositionListVO convert(PositionUserDTO positionUserDTO) {
        if (null == positionUserDTO){
            return null;
        }
        PositionListVO positionListVO = BeanUtils.toBean(positionUserDTO, PositionListVO.class);
        positionListVO.setPositionName(positionUserDTO.getName());
        DateTimeFormatter df = DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN);
        if (null != positionUserDTO.getCreateTime()){
            positionListVO.setCreateTime(positionUserDTO.getCreateTime().format(df));
        }
        return positionListVO;
    }
}
